/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.worlds.object;

import java.awt.Color;
import net.worlds.WorldsException;
import net.worlds.PropChangeHandler;
import net.worlds.ui.edge.ETextBox;

/**
 *
 * @author Jacob
 */
public class UITextBox extends UIComponent{
    private String text = null;
    public UITextBox() throws WorldsException
    {
        super("UITextBox");
        component = new ETextBox(null, 0, 0, 0, 0);
        addPropChangeHandler("BackgroundColor", new PropChangeHandler()
        {
            @Override
            public void handle(Object oldValue, Object value) throws WorldsException {
                ((ETextBox)component).setBackgroundColor(((Color)value));
            }
        });
        addPropChangeHandler("BorderColor", new PropChangeHandler()
        {
            @Override
            public void handle(Object oldValue, Object value) throws WorldsException {
                ((ETextBox)component).setBorderColor(((Color)value));
            }
        });
        addPropChangeHandler("TextColor", new PropChangeHandler()
        {
            @Override
            public void handle(Object oldValue, Object value) throws WorldsException {
                ((ETextBox)component).setTextColor(((Color)value));
            }
        });
        addPropChangeHandler("Text", new PropChangeHandler()
        {
            @Override
            public void handle(Object oldValue, Object value) throws WorldsException {
                text = value.toString();
                if(component != null)
                    ((ETextBox)component).setText(text);
            }
        });
    }
    @Override
    public Object getProp(String k) throws WorldsException
    {
        if(k.equals("Text"))
        {
            if(component == null)
                return text;
            else
                return ((ETextBox)component).getText();
        }
        return super.getProp(k);
    }
    @Override
    public void destroy()
    {
        ((ETextBox)component).setVisible(false);
        super.destroy();
    }
    @Override
    public void add()
    {
        ((ETextBox)component).setVisible(true);
    }
}
